//
//  TitleTableCell.m
//  s.
//
//  Created by fanshijian on 2022/8/30.
//  Copyright © 2022 J. All rights reserved.
//

#import "TitleTableCell.h"
#import "TitleModel.h"

@interface TitleTableCell ()

@property (weak, nonatomic) UILabel *titleLab;
@property (weak, nonatomic) UIImageView *arrowView;
@property (weak, nonatomic) UILabel *detailLab;
@end

@implementation TitleTableCell

- (UILabel *)titleLab {
    if (!_titleLab) {
        UILabel *obj = [UILabel new];
        [self addSubview:_titleLab = obj];
        [obj mas_makeConstraints:^(MASConstraintMaker *make) {
            kMakeLV(12);
            kMakeRV(-12);
            kMakeCenterYV(0);
        }];
        obj.font = U_bfont(16);
        obj.textColor = KLColor(@"#000000");
        
        [self arrowView];
    }
    return _titleLab;
}

- (UILabel *)detailLab {
    if (!_detailLab) {
        UILabel *obj = [UILabel new];
        [self.contentView addSubview:_detailLab = obj];
        [obj mas_makeConstraints:^(MASConstraintMaker *make) {
            kMakeR(self.arrowView.mas_left).offset(-10);
            kMakeL(self.titleLab.mas_left).offset(10);
            kMakeCenterYV(0);
        }];
        obj.font = U_font(16);
        obj.textColor = KLColor(@"#000000");
        obj.textAlignment = NSTextAlignmentRight;
    }
    return _detailLab;
}

- (UIImageView *)arrowView {
    if (!_arrowView) {
        UIImageView *obj = [UIImageView new];
        [self.contentView addSubview:_arrowView = obj];
        [obj mas_makeConstraints:^(MASConstraintMaker *make) {
            kMakeWHV(18, 18);
            kMakeRV(-17);
            kMakeCenterYV(0);
        }];
        obj.image = U_imageNamed(@"pb_arrow");
    }
    return _arrowView;
}

- (void)setModel:(TitleModel *)model {
    if (self.model != model || model.modified) {
        [super setModel:model];
        if (model.tf) {
            self.titleLab.font = model.tf;
        }else {
            self.titleLab.font = U_bfont(16);
        }
        self.titleLab.text = model.title?:@"";
        self.titleLab.textAlignment = model.textAlignment;
        if (model.tColor) {
            self.titleLab.textColor = KLColor(model.tColor);
        }else {
            self.titleLab.textColor = KLColor(@"#000000");
        }
        if (model.titleMakerBlock) {
            [self.titleLab mas_updateConstraints:model.titleMakerBlock];
        }
        
        if (model.color) {
            self.backgroundColor = KLColor(model.color);
        }else {
            self.backgroundColor = [UIColor clearColor];
        }
        if (model.value) {
            self.detailLab.text = model.value;
            self.detailLab.hidden = NO;
        } else {
            self.detailLab.hidden = YES;
        }
    }
}


@end
